package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.TUserLogEntity;
import com.company.project.service.TUserLogService;



/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2023-11-29 18:12:50
 */
@Controller
@RequestMapping("/")
public class TUserLogController {
    @Autowired
    private TUserLogService tUserLogService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/tUserLog")
    public String tUserLog() {
        return "tuserlog/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("tUserLog/add")
    @RequiresPermissions("tUserLog:add")
    @ResponseBody
    public DataResult add(@RequestBody TUserLogEntity tUserLog){
        tUserLogService.save(tUserLog);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("tUserLog/delete")
    @RequiresPermissions("tUserLog:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tUserLogService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("tUserLog/update")
    @RequiresPermissions("tUserLog:update")
    @ResponseBody
    public DataResult update(@RequestBody TUserLogEntity tUserLog){
        tUserLogService.updateById(tUserLog);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("tUserLog/listByPage")
    @RequiresPermissions("tUserLog:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody TUserLogEntity tUserLog){
        Page page = new Page(tUserLog.getPage(), tUserLog.getLimit());
        LambdaQueryWrapper<TUserLogEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.like(TUserLogEntity::getUserid,tUserLog.getUserid());
        queryWrapper.like(TUserLogEntity::getCompany,tUserLog.getCompany());
        queryWrapper.orderByDesc(TUserLogEntity::getEndtime);
        //查询条件示例
        //queryWrapper.eq(TUserLogEntity::getId, tUserLog.getId());
        IPage<TUserLogEntity> iPage = tUserLogService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
